<template>
  <div class="user-info" v-if="user != null">
    <!-- /user/profile　是以后部署之后才能是一定，现在ｏｓｓ项目里面没有此功能 -->
    <a href="/user/profile">个人中心</a>
    <a href="#" @click="logout">退出登录</a>
  </div>
</template>
<style scoped>
.user-info {
  float: right;
  padding-right: 20px;
}
</style>
<script>
import axios from "axios";
export default {
  data() {
    return {
      user: null
    };
  },
  mounted() {
    // 加载用户信息
    axios.get("/api/user-center/user-info").then(response => {
      this.user = response.data;
    });
  },
  methods: {
    logout() {
      axios
        .post("/api/logout")
        .then(response => {
          this.$router.push("/login");
        })
        .catch(response => {
          //console.log(response);
          alert("退出登录出现问题");
        });
    }
  }
};
</script>